<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>数据恢复</title>
    <link href="__STATIC__/component/pear/css/pear.css" rel="stylesheet"/>
    {include file='public/head.html'}
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body" style="padding:0;">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li><a href="{:url('index')}">数据管理</a></li>
                <li class="layui-this" href="{:url('restore')}">数据还原</li>
            </ul>
        </div>
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"
               data-auth-restore="{:check_auth('bak_restore')}"
               data-auth-down="{:check_auth('bak_down')}"
               data-auth-remove="{:check_auth('bak_del')}"
        ></table>
    </div>
</div>

<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
    layui.use(['aphpTable', 'aphp'], function () {
        var aphpTable = layui.aphpTable;
        var aphp = layui.aphp;
        var $ = layui.$;

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
        };

        aphpTable.render({
            init: init,
            url: "{:url('restore')}",
            toolbar: ['refresh_table'],
            search: false,
            cols: [
                [
                    {title: '备份编号', field: 'name', width: 100},
                    {title: '备份路径', field: 'path', width: 220},
                    {title: '更新时间', field: 'time'},
                    {
                        title: '操作', align: 'center', width: 160, templet: aphpTable.formatter.tool, operat: [
                            [{
                                title: '还原数据',
                                text: '',
                                class: 'layui-btn layui-btn-sm',
                                icon: 'layui-icon layui-icon-refresh-3',
                                url: "{:url('bak_restore')}",
                                method: 'none',
                                field_name: 'path',
                                auth: 'restore',
                                extend: 'data-event="restore"',
                            }],
                            [{
                                title: '下载备份',
                                text: '',
                                class: 'layui-btn layui-btn-normal layui-btn-sm',
                                icon: 'layui-icon layui-icon-download-circle',
                                url: "{:url('bak_down')}",
                                method: 'none',
                                field_name: 'path',
                                auth: 'down',
                                extend: 'data-event="down"',
                            }],
                            [{
                                title: '删除备份',
                                text: '',
                                class: 'layui-btn layui-btn-danger layui-btn-sm',
                                icon: 'layui-icon layui-icon layui-icon-delete',
                                url: "{:url('bak_del')}",
                                method: 'request',
                                field_name: 'path',
                                auth: 'remove',
                                confirm: true,
                            }],
                        ]
                    }
                ]
            ],
            page: {}
        });
        aphpTable.bindEvent();

        // 下载
        $(document).on('click', "[data-event='down']", function () {
            var url = $(this).data('href');
            layer.confirm('确定要下载备份吗?', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                window.location.href = url;
            });
        });

        // 还原
        $(document).on('click', "[data-event='restore']", function () {
            var url = $(this).data('href');
            layer.confirm('确定要还原备份吗?', {btn: ['确定', '取消']}, function (index) {
                layer.close(index);
                var loadIndex = layer.msg('数据还原中，请耐心等待……', {icon: 16, time: 60000});
                $.get(url, function (ret) {
                    if (ret.status === 1) {
                        layer.alert(ret.msg, {icon: 1, title: '提示'});
                    } else {
                        layer.alert(ret.msg, {icon: 2, title: '提示'});
                    }
                    layer.close(loadIndex);
                }, 'json');
            });
        });

    });
</script>
</body>
</html>